package cn.edu.nwafu.nic.nucleic_acid_test.services;

import cn.edu.nwafu.nic.nucleic_acid_test.dao.FormDataDao;
import cn.edu.nwafu.nic.nucleic_acid_test.dao.UserDao;
import cn.edu.nwafu.nic.nucleic_acid_test.entities.FormData;
import cn.edu.nwafu.nic.nucleic_acid_test.entities.User;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Select;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author: SungLee
 * @date: 2022-02-21 20:59
 * @description: 用户service
 */
@Service
public class FormDataService extends ServiceImpl<FormDataDao,HashMap<String,Object>> {
    private static final Logger logger = LoggerFactory.getLogger(FormDataService.class);
    @Autowired
    private FormDataDao formDataDao;

    /**
     * 检测总数
     * */
    public Integer testedCount(){
        return formDataDao.testedCount();
    }

    /**
     * 计算核酸检测完成率
     */
    public HashMap<String,Object> calFinishRate(HashMap<String,Object> formDataMap){
        double totalNum = Double.parseDouble(formDataMap.get("total_num").toString());
        double testedNum = Double.parseDouble(formDataMap.get("tested_num").toString());
        formDataMap.put("finished_rate",testedNum/totalNum);
        return formDataMap;
    }

    /**
     * 教职工核酸检测统计汇总
     */
    public HashMap<String,Object> jzgCount(){
        /*ArrayList<HashMap<String,Object>> jzgTestedStatisticsList = formDataDao.jzgTestedStatistics();
        int totalNum = 0;
        int tesedNum = 0;
        int notTestNum = 0;
        for(HashMap<String,Object> data:jzgTestedStatisticsList){
            totalNum += Integer.parseInt(data.get("total_num").toString());
            tesedNum += Integer.parseInt(data.get("tested_num").toString());
            notTestNum += Integer.parseInt(data.get("no_test_num").toString());
        }
        HashMap<String,Integer> jzgCountMap = new HashMap<>();
        jzgCountMap.put("totalNum",totalNum);
        jzgCountMap.put("tesedNum",tesedNum);
        jzgCountMap.put("notTestNum",notTestNum);*/
        HashMap<String, Object> jzgCountMap = formDataDao.jzgCount();
        return calFinishRate(jzgCountMap);
    }

    /**
     * 本科生核酸检测统计汇总
     */
    public HashMap<String,Object> bksCount(){
        HashMap<String,Object> bksCountMap = formDataDao.bksCount();
        return calFinishRate(bksCountMap);
    }

    /**
     * 研究生核酸检测统计汇总
     */
    public HashMap<String,Object> yjsCount(){
        HashMap<String,Object> yjsCountMap = formDataDao.yjsCount();
        return calFinishRate(yjsCountMap);
    }

    /**
     * 教职工核酸检测按部门统计
     */
    public ArrayList<HashMap<String,Object>> jzgTestedStatistics(){
        ArrayList<HashMap<String,Object>> formDataList = formDataDao.jzgTestedStatistics();
        for(HashMap<String,Object> formDataMap : formDataList){
            calFinishRate(formDataMap);
        }
        return formDataList;
    }

    /**
     * 本科生核酸检测按部门统计
     */
    public ArrayList<HashMap<String,Object>> bksTestedStatistics(){
        ArrayList<HashMap<String,Object>> formDataList = formDataDao.bksTestedStatistics();
        for(HashMap<String,Object> formDataMap : formDataList){
            calFinishRate(formDataMap);
        }
        return formDataList;
    }

    /**
     * 研究生核酸检测按部门统计
     */
    public ArrayList<HashMap<String,Object>> yjsTestedStatistics(){
        ArrayList<HashMap<String,Object>> formDataList = formDataDao.yjsTestedStatistics();
        for(HashMap<String,Object> formDataMap : formDataList){
            calFinishRate(formDataMap);
        }
        return formDataList;
    }

    /**
     * 教职工未检测人员列表
     */
    public ArrayList<HashMap<String,Object>> jzgNotTestList(String dept){
        return formDataDao.jzgNotTestList(dept);
    }

    /**
     * 本科生未检测人员列表
     */
    public ArrayList<HashMap<String,Object>> bksNotTestList(String dept){
        return formDataDao.bksNotTestList(dept);
    }

    /**
     * 研究生未检测人员列表
     */
    public ArrayList<HashMap<String,Object>> yjsNotTestList(String dept){
        return formDataDao.yjsNotTestList(dept);
    }
}
